package link.anyauto.fsmgr.biz.main;

import android.databinding.DataBindingUtil;

import java.util.ArrayList;
import java.util.List;

import link.anyauto.fsmgr.R;
import link.anyauto.fsmgr.base.ActBase;
import link.anyauto.fsmgr.base.BaseNames;
import link.anyauto.fsmgr.databinding.ActMainBinding;
import link.anyauto.fsmgr.domain.Function;
import link.anyauto.fsmgr.domain.FunctionGroup;
import link.anyauto.fsmgr.vo.FunctionGroupVO;

/**
 * Created by Administrator on 2016/7/17.
 */
public class ActMain extends ActBase {

    protected void initBinding() {
        binding = DataBindingUtil.setContentView(this, R.layout.act_main);
    }

    protected void initVM() {
        vm = new MainVM();
        vm.account = getIntent().getStringExtra(BaseNames.KEY_ACCOUNT);
        List<FunctionGroupVO> groups = mockFunctions();
        vm.groups = groups;
        adapter = new FunctionsAdapter(groups);
    }

    protected void initHandlers(){
        handlers = new MainHandlers();
    }

    @Override
    protected void postInit() {
        binding.setVm(vm);
        binding.setHandlers(handlers);
        binding.functionList.setAdapter(adapter);
        handlers.vm = vm;
        handlers.context = this;
    }

    @Override
    protected void unbind() {
        binding.unbind();
    }

    List<FunctionGroupVO> mockFunctions() {
        List<FunctionGroupVO> groups = new ArrayList<>();

        FunctionGroup g = new FunctionGroup();
        g.name = "客户";
        g.functions = new ArrayList<>();

        Function func = new Function();
        func.name = "创建客户";
        func.action = BaseNames.ACTION_CLIENT_PORTFOLIO;
        g.functions.add(func);

        func = new Function();
        func.name = "浏览客户";
        g.functions.add(func);
        groups.add(new FunctionGroupVO(g));

        g = new FunctionGroup();
        g.name = "报价";
        g.functions = new ArrayList<>();

        func = new Function();
        func.name = "到店报价";
        g.functions.add(func);
        groups.add(new FunctionGroupVO(g));

        return groups;
    }

    MainVM vm;
    MainHandlers handlers;
    ActMainBinding binding;
    FunctionsAdapter adapter;
}
